package com.veer.shop.repository;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.veer.shop.mapper.CustomerMapper;
import com.veer.shop.param.CustomerListParam;
import com.veer.shop.result.CustomerBaseResult;
import com.veer.shop.result.CustomerRepoResult;
import com.veer.shop.utils.StringUtil;
import com.veer.shop.utils.SystemConfigUtil;

/**
 * 会员相关对象获取组装类
 *
 * @author WangBin
 * @date 2021/1/3 21:35
 */
@Component
public class CustomerRepository {

	@Autowired
	private CustomerMapper customerMapper;
	
	/**
	 * 根据ID查询会员信息
	 * 
	 * @param customerId
	 */
    public CustomerBaseResult getCustomerById(Integer customerId) {
    	return new CustomerBaseResult();
    }
    
    /**
     * 根据手机号查询会员信息
     * 
     * @param phone
     * @return
     */
    public CustomerBaseResult getCustomerByPhone(String phone) {
		return customerMapper.getCustomerByPhone(phone);
	}
    
    /**
     * 获取会员列表数据
     * 
     * @param param
     * @return
     * @throws NoSuchMethodException
     * @throws SecurityException
     */
    public List<CustomerRepoResult> getList(CustomerListParam param)
    {
    	List<CustomerRepoResult> customerRepoList = new ArrayList<CustomerRepoResult>();
    	CustomerRepoResult customerRepoResult = new CustomerRepoResult();
    	List<Map<String,Object>> customerList = customerMapper.getList(param);
    	for (Map<String, Object> map : customerList) {
    		customerRepoResult.setCustomerId((Long)map.get("customer_id"));
    		customerRepoResult.setCustomerBn((String)map.get("customer_bn"));
    		customerRepoResult.setNickname((String)map.get("nickname"));
    		customerRepoResult.setBirthday((String)map.get("birthday"));
    		customerRepoResult.setCheckedAt((Date)map.get("checked_at"));
    		customerRepoResult.setCreatedAt((Date)map.get("created_at"));
    		customerRepoResult.setCustomerType((String)map.get("customer_type"));
    		customerRepoResult.setRealname((String)map.get("realname"));
    		customerRepoResult.setEmail((String)map.get("email"));
    		customerRepoResult.setPhone((String)map.get("phone"));
    		customerRepoResult.setGender((String)map.get("gender"));
    		customerRepoResult.setGenderName(SystemConfigUtil.getKeyValue(customerRepoResult.getGender()));
    		customerRepoList.add(customerRepoResult);
		}
    	return customerRepoList;
    }
}
